package com.lwf.fatapi.mapper;

import com.lwf.fatapi.entities.Project;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 项目 Mapper 接口
 *
 * @author lwf
 */
@Mapper
public interface ProjectMapper extends BaseMapper<Project> {

    /**
     * 根据项目编码查询项目
     */
    @Select("SELECT * FROM project WHERE project_code = #{projectCode} AND is_deleted = 0")
    Project selectByProjectCode(@Param("projectCode") String projectCode);

    /**
     * 检查项目名称是否存在
     */
    @Select("SELECT COUNT(*) FROM project WHERE project_name = #{projectName} AND is_deleted = 0 AND id != #{excludeId}")
    int countByProjectName(@Param("projectName") String projectName, @Param("excludeId") Long excludeId);

    /**
     * 检查项目编码是否存在
     */
    @Select("SELECT COUNT(*) FROM project WHERE project_code = #{projectCode} AND is_deleted = 0 AND id != #{excludeId}")
    int countByProjectCode(@Param("projectCode") String projectCode, @Param("excludeId") Long excludeId);
}
